/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GuiClient.java
 *
 * Created on 27-feb-2012, 19:13:49
 */
package ants;

import java.awt.*;

/**
 *
 * @author Blanca
 */
public class GuiClient extends javax.swing.JFrame {
    FTablero c1, c2, c3;
    boolean activated = false;
    boolean run = true;
    Mapa m;
    /** Creates new form GuiClient */
    public GuiClient(Mapa map) {
        m = map;
        c1 = new FTablero(m,0, true, 5);
        c2 = new FTablero(m,1, true, 5);
        c3 = new FTablero(m,0, false, 5);
        c1.setBackground(Color.yellow);
        initComponents();
        this.add(c1);
        /*this.jPanel1.setVisible(true);
        this.jPanel1.add(c1);
        this.jPanel2.add(c2);
        this.jPanel3.add(c3);*/
    }
    public void getMap(Mapa map){
        //System.out.println("canvas asdf");
        if(activated == false)
            activated = true;
        m = map;
        c1.getMap(map);
        c2.getMap(map);
        c3.getMap(map);
        repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 324, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        run = false;
    }//GEN-LAST:event_formWindowClosed
    @Override public void paint(Graphics g){
        Image buffer = createImage(this.getSize().width, this.getSize().height);
        Graphics g2 = buffer.getGraphics();
        g.setColor(Color.black);
        //System.out.println("HUEHUEHUE");
        int pheromone = 0;
        int tilesize = 0;
        boolean t = true;
        if(activated == true){
        if (t == true){
            System.out.println("Fermona:");
            for(int i = 0; i < m.cells.length; i++){
                for(int j = 0; j < m.cells[0].length; j++){
                    try {
                    if(m.cells[i][j].tipo == Constantes.obstaculo){
                        g.setColor(Color.black);
                    }
                    else{
                        switch(pheromone){
                            case 0: g.setColor(new Color(255, 0, 0)); System.out.print("["+m.cells[i][j].getPheromone(0) +"]");break;
                            case 1: g.setColor(new Color(0, 255, 0));break;
                        }
                    }}catch(Exception e){ System.out.println("ERROR: y: " +i+ " x: "+j);System.out.println(" MAX: " +i+ " x: "+j);}
                    g2.drawRect(j+(j*tilesize), i+(i*tilesize), tilesize, tilesize);
                }
                System.out.println();
            }
        }
        else{
            for(int i = 0; i < m.cells.length; i++){
                for(int j = 0; j < m.cells[0].length; j++){
                    g2.drawString(m.cells[i][j].getDir()+":"+m.cells[i][j].getDist(), j+(j*tilesize), i+(i*tilesize));
                }
            }
        }
        g.drawImage(buffer, 0, 0, this);
        }
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(GuiClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(GuiClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(GuiClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(GuiClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new GuiClient().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables
}
